package com.lmt.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Zuul请求重试Controller
 * Date 2018/07/22
 *
 * @author MT-Lin
 */
@RestController
public class ZuulRetryController {

    private Logger logger = LoggerFactory.getLogger(ZuulRetryController.class);

    private final RestTemplate restTemplate;

    @Autowired
    public ZuulRetryController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @RequestMapping("/zuulRetry")
    public String zuulRetry(@RequestParam(name = "retryMark") String retryMark){
        logger.warn("consumer-ribbon->zuulRetry():retryMark is {}", retryMark);
        String url = "http://provider/zuulRetry?retryMark=" + retryMark;
        return this.restTemplate.getForObject(url, String.class);
    }
}
